var e = require("../@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var t = e(require("@vant/weapp/dialog/dialog.js")), a = e(require("../utils/Tips")), o = e(require("../api/api_queryRemain.js")), n = e(require("../api/auth.js")), i = getApp(), r = Behavior({
    behaviors: [],
    properties: {},
    data: {
        phone: "",
        hasAuth: !1,
        userStatus: ""
    },
    attached: function() {},
    methods: {
        beforeDialog: function() {
            var e = this.data.nativeComponentShow;
            void 0 !== e && e && this.setData({
                nativeComponentShow: !1
            });
        },
        offAuthListener: function() {
            this.changeAuthInfo_sub && this.changeAuthInfo_sub.off(), this.changeUserAuth_sub && this.changeUserAuth_sub.off();
        },
        getAuthUserInfo: function() {
            var e = this, n = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, r = n.forceUpdate, u = void 0 !== r && r, d = n.needAuth, s = void 0 !== d && d;
            return new Promise(function(n, r) {
                u || !i.globalData.hasAuth ? (a.default.loading(), o.default.getUserInfo().then(function(o) {
                    if (a.default.loaded(), console.log(o), "0" !== o.code) return e.beforeDialog(), 
                    void t.default.alert({
                        context: e,
                        message: o.message,
                        overlayStyle: {
                            background: "white"
                        }
                    });
                    var r = o.data, u = r.hasAuth, d = r.phone, l = r.cardTag;
                    i.globalData.phone = d, i.globalData.hasAuth = u;
                    var h = "";
                    h = d ? 0 === l ? "NOTWK" : "WK" : "NOTBIND", e.setData({
                        phone: d,
                        hasAuth: u,
                        userStatus: h
                    }), s && !o.data.hasAuth && (e.beforeDialog(), t.default.alert({
                        context: e,
                        message: "您需要授权“王卡助手”微信小程序，才可继续使用",
                        confirmButtonOpenType: "getUserInfo",
                        confirmButtonText: "立即授权",
                        overlayStyle: {
                            background: "white"
                        }
                    })), n(o);
                }).catch(function(e) {
                    r(e), a.default.loaded();
                })) : n({
                    hasAuth: !0
                });
            });
        },
        bindgetphonenumber: function(e) {
            var t = i.globalData.bindurl;
            wx.navigateTo({
                url: "/pages/webview/index?url=".concat(encodeURIComponent("".concat(t, "/KCardAuth/redirect?env=wx_bind&loginType=2&checkType=1&redirectUrl=").concat(encodeURIComponent(t), "%2FKCard%2FmPages%2Fbinded.html")))
            });
        },
        bindgetuserinfo: function(e) {
            var o = this;
            e.detail.iv && e.detail.encryptedData && (a.default.loading(), n.default.auth({
                source: 1,
                encryptedData: e.detail.encryptedData,
                iv: e.detail.iv
            }).then(function(e) {
                a.default.loaded(), o.afterBinduserinfo && o.afterBinduserinfo(e);
            }).catch(function() {
                a.default.loaded(), o.beforeDialog(), t.default.alert({
                    context: o,
                    message: "授权失败，请重试"
                });
            }));
        }
    }
});

exports.default = r;